#include "Circle.h"

Circle::Circle(const Vector2D& center, const float radius)
{
	Init(center.x, center.y, radius);
}

Circle::Circle(const float x, const float y, const float radius)
{
	Init(x, y, radius);
}

void Circle::Init(const float x, const float y, const float radius)
{
	this->x = x;
	this->y = y;
	this->r = radius;
}

bool Circle::Contains(const Vector2D& point)
{
	return Contains(point.x, point.y);
}

bool Circle::Contains(const float x,const float y)
{
	Vector2D v = {x - this->x, y - this ->y};
	return Vector2D::Length(v) < this->r;
	Contains(v);
}


void Circle::SetPosition(const Vector2D& vect)
{
	SetPosition(vect.x, vect.y);
}

void Circle::SetPosition(const float x,const float y)
{
	this->x = x;
	this->y = y;
}

void Circle::MoveBy(const Vector2D& vect)
{
	SetPosition(vect.x + x, vect.y + y);
}

void Circle::MoveBy(const float x,const float y)
{
	SetPosition(x + this->x, y + this->y);
}

bool Circle::CollidesWith(const Circle& circ)
{
	Vector2D v = {this->x - circ.GetX(), this->y - circ.GetY()};

	return Vector2D::Length(v) < (this->r + circ.GetRadius());
}


bool Circle::CollidesWith(const Rectangle& rect)
{
	float testX = x;
    float testY = y;

	if (testX < rect.GetX())
	{
        testX = rect.GetX();
	}
    if (testX > (rect.GetX() + rect.GetWidth()))
	{
        testX = (rect.GetX() + rect.GetWidth());
	}

    if (testY < rect.GetY())
	{
        testY = rect.GetY();
	}
    if (testY > (rect.GetY() + rect.GetHeight()))
	{
        testY = (rect.GetY() + rect.GetHeight());
	}

	 return ((x - testX) * (x - testX) + (y - testY) * (y - testY)) < r * r;
}

bool Circle::Equals(const Circle& circ)
{
	return this->x == circ.GetX() && this->y == circ.GetY() && this->r == circ.GetRadius();
}